<?php
/*
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
	
	---------------------------------------------------------------------
	
    Name:		NZ Post Shipping Module Plus
	
	OpenCart:	Version 1.5.4.1
    
    Copyright:  2012 rebdog (Godfrey) godfrey@satelliteshop.co.nz
                2011-2012 Andy Carroll andy@goldfishinteractive.co.nz
 
    If you're going to use the code, give some credit.. it's simple

*/
class ControllerShippingNZPost extends Controller {
	private $error = array(); 
	
	public function index() {
		$this->load->language('shipping/nzpost');
			
		$this->document->setTitle($this->language->get('heading_title'));
		
		$this->load->model('setting/setting');
				
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
			$this->model_setting_setting->editSetting('nzpost', $this->request->post);		
					
			$this->session->data['success'] = $this->language->get('text_success');
						
			$this->redirect($this->url->link('extension/shipping', 'token=' . $this->session->data['token'], 'SSL'));
		}
		
		$this->data['heading_title'] = $this->language->get('heading_title');
		
		$this->data['text_enabled'] = $this->language->get('text_enabled');
		$this->data['text_disabled'] = $this->language->get('text_disabled');
		$this->data['text_yes'] = $this->language->get('text_yes');
		$this->data['text_no'] = $this->language->get('text_no');		
		$this->data['text_select_all'] = $this->language->get('text_select_all');
		$this->data['text_unselect_all'] = $this->language->get('text_unselect_all');		
		$this->data['text_all_zones'] = $this->language->get('text_all_zones');
		$this->data['text_none'] = $this->language->get('text_none');
			
		$this->data['text_nzpost_international_tracking'] = $this->language->get('text_international_tracking');
		$this->data['text_nzpost_international_signature'] = $this->language->get('text_international_signature');      
        $this->data['text_pp_untracked_tickets'] = $this->language->get('text_pp_untracked_tickets');
        $this->data['text_pp_untracked_fast_tickets'] = $this->language->get('text_pp_untracked_fast_tickets');
        $this->data['text_pp_tracked_3kg_tickets'] = $this->language->get('text_pp_tracked_3kg_tickets');
        $this->data['text_pp_tracked_5kg_tickets'] = $this->language->get('text_pp_tracked_5kg_tickets');
        $this->data['text_pp_tracked_zonal_across_town_tickets'] = $this->language->get('text_pp_tracked_zonal_across_town_tickets');
        $this->data['text_pp_tracked_zonal_within_island_tickets'] = $this->language->get('text_pp_tracked_zonal_within_island_tickets');
        $this->data['text_pp_tracked_zonal_nationwide_tickets'] = $this->language->get('text_pp_tracked_zonal_nationwide_tickets');
        $this->data['text_pp_untracked_flat_bags'] = $this->language->get('text_pp_untracked_flat_bags');
        $this->data['text_pp_untracked_fast_flat_bags'] = $this->language->get('text_pp_untracked_fast_flat_bags');
        $this->data['text_pp_untracked_bubble_bags'] = $this->language->get('text_pp_untracked_bubble_bags');
        $this->data['text_pp_untracked_fast_bubble_bags'] = $this->language->get('text_pp_untracked_fast_bubble_bags');
        $this->data['text_pp_tracked_flat_bags'] = $this->language->get('text_pp_tracked_flat_bags');
        $this->data['text_pp_tracked_bubble_bags'] = $this->language->get('text_pp_tracked_bubble_bags');
        $this->data['text_courier_zonal_across_town_tickets'] = $this->language->get('text_courier_zonal_across_town_tickets');
        $this->data['text_courier_zonal_within_island_tickets'] = $this->language->get('text_courier_zonal_within_island_tickets');
        $this->data['text_courier_zonal_nationwide_tickets'] = $this->language->get('text_courier_zonal_nationwide_tickets');
        $this->data['text_courier_zonal_across_town_tickets_signature'] = $this->language->get('text_courier_zonal_across_town_tickets_signature');
        $this->data['text_courier_zonal_within_island_tickets_signature'] = $this->language->get('text_courier_zonal_within_island_tickets_signature');
        $this->data['text_courier_zonal_nationwide_tickets_signature'] = $this->language->get('text_courier_zonal_nationwide_tickets_signature');
        $this->data['text_courier_flat_bags'] = $this->language->get('text_courier_flat_bags');
        $this->data['text_courier_bubble_bags'] = $this->language->get('text_courier_bubble_bags');
        $this->data['text_courier_flat_bags_signature'] = $this->language->get('text_courier_flat_bags_signature');
  
		$this->data['entry_status'] = $this->language->get('entry_status');
		$this->data['entry_geo_zone'] = $this->language->get('entry_geo_zone');
		$this->data['entry_tax'] = $this->language->get('entry_tax');
		$this->data['entry_gst_paid_on_intl_postage'] = $this->language->get('entry_gst_paid_on_intl_postage');
		$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
		$this->data['entry_api_key'] = $this->language->get('entry_api_key');
		$this->data['entry_format'] = $this->language->get('entry_format');
		$this->data['entry_service_across_town'] = $this->language->get('entry_service_across_town');
        $this->data['entry_service_across_town_r'] = $this->language->get('entry_service_across_town_r');
        $this->data['entry_service_within_island'] = $this->language->get('entry_service_within_island');
        $this->data['entry_service_within_island_r'] = $this->language->get('entry_service_within_island_r');
        $this->data['entry_service_nationwide'] = $this->language->get('entry_service_nationwide');
        $this->data['entry_service_nationwide_r'] = $this->language->get('entry_service_nationwide_r');
		$this->data['entry_international_options'] = $this->language->get('entry_international_options');
        $this->data['entry_weight_class_id'] = $this->language->get('entry_weight_class_id');
		$this->data['entry_length_class_id'] = $this->language->get('entry_length_class_id');
        $this->data['entry_currency_code'] = $this->language->get('entry_currency_code');
		$this->data['entry_display_weight'] = $this->language->get('entry_display_weight');
        $this->data['entry_apply_filters'] = $this->language->get('entry_apply_filters');
		$this->data['entry_source_postcode'] = $this->language->get('entry_source_postcode');
		
		$this->data['button_save'] = $this->language->get('button_save');
		$this->data['button_cancel'] = $this->language->get('button_cancel');
		
        $this->data['tab_general'] = $this->language->get('tab_general');
        $this->data['tab_domestic'] = $this->language->get('tab_domestic');
        $this->data['tab_international'] = $this->language->get('tab_international');
        $this->data['tab_across_town_urban'] = $this->language->get('tab_across_town_urban');
		$this->data['tab_across_town_rural'] = $this->language->get('tab_across_town_rural');
        $this->data['tab_within_island_urban'] = $this->language->get('tab_within_island_urban');
        $this->data['tab_within_island_rural'] = $this->language->get('tab_within_island_rural');
        $this->data['tab_inter_island_urban'] = $this->language->get('tab_inter_island_urban');
        $this->data['tab_inter_island_rural'] = $this->language->get('tab_inter_island_rural');
        
        if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}

		if (isset($this->error['api_key'])) {
			$this->data['error_api_key'] = $this->error['api_key'];
		} else {
			$this->data['error_api_key'] = '';
		}

		if (isset($this->error['source_postcode'])) {
			$this->data['error_source_postcode'] = $this->error['source_postcode'];
		} else {
			$this->data['error_source_postcode'] = '';
		}

		if (isset($this->error['length_class_id'])) {
			$this->data['error_length_class_id'] = $this->error['length_class_id'];
		} else {
			$this->data['error_length_class_id'] = '';
        }

        if (isset($this->error['weight_class_id'])) {
			$this->data['error_weight_class_id'] = $this->error['weight_class_id'];
		} else {
			$this->data['error_weight_class_id'] = '';
        }
        if (isset($this->error['currency_code'])) {
			$this->data['error_currency_code'] = $this->error['currency_code'];
		} else {
			$this->data['error_currency_code'] = '';
        }
        
  		$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_shipping'),
			'href'      => $this->url->link('extension/shipping', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		
   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('shipping/nzpost', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		
		$this->data['action'] = $this->url->link('shipping/nzpost', 'token=' . $this->session->data['token'], 'SSL');
		
		$this->data['cancel'] = $this->url->link('extension/shipping', 'token=' . $this->session->data['token'], 'SSL');
		
		if (isset($this->request->post['nzpost_api_key'])) {
			$this->data['nzpost_api_key'] = $this->request->post['nzpost_api_key'];
		} else {
			$this->data['nzpost_api_key'] = $this->config->get('nzpost_api_key');
		}
		
		if (isset($this->request->post['nzpost_source_postcode'])) {
			$this->data['nzpost_source_postcode'] = $this->request->post['nzpost_source_postcode'];
		} else {
			$this->data['nzpost_source_postcode'] = $this->config->get('nzpost_source_postcode');
		}
		       
        if (isset($this->request->post['nzpost_weight_class_id'])) {
			$this->data['nzpost_weight_class_id'] = $this->request->post['nzpost_weight_class_id'];
		} else {
			$this->data['nzpost_weight_class_id'] = $this->config->get('nzpost_weight_class_id');
		}
		
		$this->load->model('localisation/weight_class');
		
		$this->data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses();
			
		if (isset($this->request->post['nzpost_length_class_id'])) {
			$this->data['nzpost_length_class_id'] = $this->request->post['nzpost_length_class_id'];
		} else {
			$this->data['nzpost_length_class_id'] = $this->config->get('nzpost_length_class_id');
		}
				
		$this->load->model('localisation/length_class');
		
		$this->data['length_classes'] = $this->model_localisation_length_class->getLengthClasses();


		if (isset($this->request->post['nzpost_currency_code'])) {
			$this->data['nzpost_currency_code'] = $this->request->post['nzpost_currency_code'];
		} else {
			$this->data['nzpost_currency_code'] = $this->config->get('nzpost_currency_code');
		}
				
		$this->load->model('localisation/currency');
		
		$this->data['currencies'] = $this->model_localisation_currency->getCurrencies();
        
        
        if (isset($this->request->post['nzpost_display_weight'])) {
			$this->data['nzpost_display_weight'] = $this->request->post['nzpost_display_weight'];
		} else {
			$this->data['nzpost_display_weight'] = $this->config->get('nzpost_display_weight');
		}
		
		if (isset($this->request->post['nzpost_apply_filters'])) {
			$this->data['nzpost_apply_filters'] = $this->request->post['nzpost_apply_filters'];
		} else {
			$this->data['nzpost_apply_filters'] = $this->config->get('nzpost_apply_filters');
		}
        
		if (isset($this->request->post['nzpost_gst_paid_on_intl_postage'])) {
			$this->data['nzpost_gst_paid_on_intl_postage'] = $this->request->post['nzpost_gst_paid_on_intl_postage'];
		} else {
			$this->data['nzpost_gst_paid_on_intl_postage'] = $this->config->get('nzpost_gst_paid_on_intl_postage');
		}
								
		if (isset($this->request->post['nzpost_tax_class_id'])) {
			$this->data['nzpost_tax_class_id'] = $this->request->post['nzpost_tax_class_id'];
		} else {
			$this->data['nzpost_tax_class_id'] = $this->config->get('nzpost_tax_class_id');
		}
		
		$this->load->model('localisation/tax_class');
		
		$this->data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses();
		
		if (isset($this->request->post['nzpost_geo_zone_id'])) {
			$this->data['nzpost_geo_zone_id'] = $this->request->post['nzpost_geo_zone_id'];
		} else {
			$this->data['nzpost_geo_zone_id'] = $this->config->get('nzpost_geo_zone_id');
		}
		
		$this->load->model('localisation/geo_zone');
		
		$this->data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
		
		if (isset($this->request->post['nzpost_status'])) {
			$this->data['nzpost_status'] = $this->request->post['nzpost_status'];
		} else {
			$this->data['nzpost_status'] = $this->config->get('nzpost_status');
		}

		if (isset($this->request->post['nzpost_sort_order'])) {
			$this->data['nzpost_sort_order'] = $this->request->post['nzpost_sort_order'];
		} else {
			$this->data['nzpost_sort_order'] = $this->config->get('nzpost_sort_order');
		}	
        
        if (isset($this->request->post['nzpost_service_across_town'])) {
			$this->data['nzpost_service_across_town'] = $this->request->post['nzpost_service_across_town'];
		} elseif ($this->config->has('nzpost_service_across_town')) {
			$this->data['nzpost_service_across_town'] = $this->config->get('nzpost_service_across_town');
		} else {
			$this->data['nzpost_service_across_town'] = array();	
		}
        
        if (isset($this->request->post['nzpost_service_across_town_r'])) {
			$this->data['nzpost_service_across_town_r'] = $this->request->post['nzpost_service_across_town_r'];
		} elseif ($this->config->has('nzpost_service_across_town_r')) {
			$this->data['nzpost_service_across_town_r'] = $this->config->get('nzpost_service_across_town_r');
		} else {
			$this->data['nzpost_service_across_town_r'] = array();	
		}
        
        if (isset($this->request->post['nzpost_service_within_island'])) {
			$this->data['nzpost_service_within_island'] = $this->request->post['nzpost_service_within_island'];
		} elseif ($this->config->has('nzpost_service_within_island')) {
			$this->data['nzpost_service_within_island'] = $this->config->get('nzpost_service_within_island');
		} else {
			$this->data['nzpost_service_within_island'] = array();	
		}
        
        if (isset($this->request->post['nzpost_service_within_island_r'])) {
			$this->data['nzpost_service_within_island_r'] = $this->request->post['nzpost_service_within_island_r'];
		} elseif ($this->config->has('nzpost_service_within_island_r')) {
			$this->data['nzpost_service_within_island_r'] = $this->config->get('nzpost_service_within_island_r');
		} else {
			$this->data['nzpost_service_within_island_r'] = array();	
		}
        
        if (isset($this->request->post['nzpost_service_nationwide'])) {
			$this->data['nzpost_service_nationwide'] = $this->request->post['nzpost_service_nationwide'];
		} elseif ($this->config->has('nzpost_service_nationwide')) {
			$this->data['nzpost_service_nationwide'] = $this->config->get('nzpost_service_nationwide');
		} else {
			$this->data['nzpost_service_nationwide'] = array();	
		}
        
        if (isset($this->request->post['nzpost_service_nationwide_r'])) {
			$this->data['nzpost_service_nationwide_r'] = $this->request->post['nzpost_service_nationwide_r'];
		} elseif ($this->config->has('nzpost_service_nationwide_r')) {
			$this->data['nzpost_service_nationwide_r'] = $this->config->get('nzpost_service_nationwide_r');
		} else {
			$this->data['nzpost_service_nationwide_r'] = array();	
		}

		$this->data['services_pp_untracked_tickets'] = array();
		
		$this->data['services_pp_untracked_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_dle'),
			'value' => 'PKTDLE'
		);
			
		$this->data['services_pp_untracked_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PKTC5'
		);
		
		$this->data['services_pp_untracked_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_c4'),
			'value' => 'PKTC4'
		);
		
		$this->data['services_pp_untracked_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_fs'),
			'value' => 'PKTFS'
		);
        
		$this->data['services_pp_untracked_fast_tickets'] = array();
		
		$this->data['services_pp_untracked_fast_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_dle'),
			'value' => 'PKTDLE_PKTEF'
		);
			
		$this->data['services_pp_untracked_fast_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PKTC5_PKTEF'
		);
		
		$this->data['services_pp_untracked_fast_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_c4'),
			'value' => 'PKTC4_PKTEF'
		);
		
		$this->data['services_pp_untracked_fast_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_fs'),
			'value' => 'PKTFS_PKTEF'
		);
        
        $this->data['services_pp_tracked_3kg_tickets'] = array();
				
		$this->data['services_pp_tracked_3kg_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PCB3C5'
		);
		
		$this->data['services_pp_tracked_3kg_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_c4'),
			'value' => 'PCB3C4'
		);
		
		$this->data['services_pp_tracked_3kg_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_fs'),
			'value' => 'PCB3FS'
		);
        
 		$this->data['services_pp_tracked_3kg_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_lf'),
			'value' => 'PCB5LF'
		);       
                
        $this->data['services_pp_tracked_3kg_tickets_r'] = array();
				
		$this->data['services_pp_tracked_3kg_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PCB3C5_PCBRURAL'
		);
		
		$this->data['services_pp_tracked_3kg_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_c4'),
			'value' => 'PCB3C4_PCBRURAL'
		);
		
		$this->data['services_pp_tracked_3kg_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_fs'),
			'value' => 'PCB3FS_PCBRURAL'
		);
        
 		$this->data['services_pp_tracked_3kg_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_lf'),
			'value' => 'PCB3LF_PCBRURAL'
		);       
        
        $this->data['services_pp_tracked_5kg_tickets'] = array();
				
		$this->data['services_pp_tracked_5kg_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PCB5C5'
		);
		
		$this->data['services_pp_tracked_5kg_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_c4'),
			'value' => 'PCB5C4'
		);
		
		$this->data['services_pp_tracked_5kg_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_fs'),
			'value' => 'PCB5FS'
		);
        
 		$this->data['services_pp_tracked_5kg_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_size_lf'),
			'value' => 'PCB5LF'
		); 
     
        $this->data['services_pp_tracked_5kg_tickets_r'] = array();
				
		$this->data['services_pp_tracked_5kg_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PCB5C5_PCBRURAL'
		);
		
		$this->data['services_pp_tracked_5kg_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_c4'),
			'value' => 'PCB5C4_PCBRURAL'
		);
		
		$this->data['services_pp_tracked_5kg_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_fs'),
			'value' => 'PCB5FS_PCBRURAL'
		);
        
 		$this->data['services_pp_tracked_5kg_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_lf'),
			'value' => 'PCB5LF_PCBRURAL'
		); 

        $this->data['services_pp_tracked_zonal_across_town_tickets'] = array();
				
		$this->data['services_pp_tracked_zonal_across_town_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'PCBXT'
		);
		
        $this->data['services_pp_tracked_zonal_across_town_tickets_r'] = array();
				
		$this->data['services_pp_tracked_zonal_across_town_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'PCBXT_PCBRURAL'
		);

        $this->data['services_pp_tracked_zonal_within_island_tickets'] = array();
				
		$this->data['services_pp_tracked_zonal_within_island_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'PCBWI'
		);

		$this->data['services_pp_tracked_zonal_within_island_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_10kg'),
			'value' => 'PCBWI_PCEWI'
		);

		$this->data['services_pp_tracked_zonal_within_island_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_15kg'),
			'value' => 'PCBWI_PCEWI_PCEWI'
		);

		$this->data['services_pp_tracked_zonal_within_island_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_20kg'),
			'value' => 'PCBWI_PCEWI_PCEWI_PCEWI'
		);

		$this->data['services_pp_tracked_zonal_within_island_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'PCBWI_PCEWI_PCEWI_PCEWI_PCEWI'
		);
		
        $this->data['services_pp_tracked_zonal_within_island_tickets_r'] = array();
				
		$this->data['services_pp_tracked_zonal_within_island_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'PCBWI_PCBRURAL'
		);

		$this->data['services_pp_tracked_zonal_within_island_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_10kg'),
			'value' => 'PCBWI_PCEWI_PCBRURAL'
		);

		$this->data['services_pp_tracked_zonal_within_island_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_15kg'),
			'value' => 'PCBWI_PCEWI_PCEWI_PCBRURAL'
		);

		$this->data['services_pp_tracked_zonal_within_island_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_20kg'),
			'value' => 'PCBWI_PCEWI_PCEWI_PCEWI_PCBRURAL'
		);

		$this->data['services_pp_tracked_zonal_within_island_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'PCBWI_PCEWI_PCEWI_PCEWI_PCEWI_PCBRURAL'
		);
             
        $this->data['services_pp_tracked_zonal_nationwide_tickets'] = array();
				
		$this->data['services_pp_tracked_zonal_nationwide_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'PCBNZ'
		);

		$this->data['services_pp_tracked_zonal_nationwide_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_10kg'),
			'value' => 'PCBNZ_PCENZ'
		);

		$this->data['services_pp_tracked_zonal_nationwide_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_15kg'),
			'value' => 'PCBNZ_PCENZ_PCENZ'
		);

		$this->data['services_pp_tracked_zonal_nationwide_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_20kg'),
			'value' => 'PCBNZ_PCENZ_PCENZ_PCENZ'
		);

		$this->data['services_pp_tracked_zonal_nationwide_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'PCBNZ_PCENZ_PCENZ_PCENZ_PCENZ'
		);
		
        $this->data['services_pp_tracked_zonal_nationwide_tickets_r'] = array();
				
		$this->data['services_pp_tracked_zonal_nationwide_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'PCBNZ_PCBRURAL'
		);

		$this->data['services_pp_tracked_zonal_nationwide_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_10kg'),
			'value' => 'PCBNZ_PCENZ_PCBRURAL'
		);

		$this->data['services_pp_tracked_zonal_nationwide_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_15kg'),
			'value' => 'PCBNZ_PCENZ_PCENZ_PCBRURAL'
		);

		$this->data['services_pp_tracked_zonal_nationwide_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_20kg'),
			'value' => 'PCBNZ_PCENZ_PCENZ_PCENZ_PCBRURAL'
		);

		$this->data['services_pp_tracked_zonal_nationwide_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'PCBNZ_PCENZ_PCENZ_PCENZ_PCENZ_PCBRURAL'
		);
        
		$this->data['services_pp_untracked_flat_bags'] = array();
		
		$this->data['services_pp_untracked_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PIKFC5'
		);
		
		$this->data['services_pp_untracked_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_c4'),
			'value' => 'PIKFC4'
		);
		
		$this->data['services_pp_untracked_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_fs'),
			'value' => 'PIKFFS'
		);

        $this->data['services_pp_untracked_fast_flat_bags'] = array();
		
		$this->data['services_pp_untracked_fast_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PIFFC5'
		);
		
		$this->data['services_pp_untracked_fast_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_c4'),
			'value' => 'PIFFC4'
		);
        
		$this->data['services_pp_untracked_bubble_bags'] = array();
		
		$this->data['services_pp_untracked_bubble_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PIKBC5'
		);
		
		$this->data['services_pp_untracked_bubble_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_c4'),
			'value' => 'PIKBC4'
		);
		
        $this->data['services_pp_untracked_fast_bubble_bags'] = array();
		
		$this->data['services_pp_untracked_fast_bubble_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PIFBC5'
		);
		
		$this->data['services_pp_untracked_fast_bubble_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_c4'),
			'value' => 'PIFBC4'
		);
                 
		$this->data['services_pp_tracked_flat_bags'] = array();
		
        $this->data['services_pp_tracked_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_dle'),
			'value' => 'PICDLE'
		);

		$this->data['services_pp_tracked_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PICFC5'
		);
		
		$this->data['services_pp_tracked_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_c4'),
			'value' => 'PICFC4'
		);
		
		$this->data['services_pp_tracked_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_fs'),
			'value' => 'PICFFS'
		);
		
		$this->data['services_pp_tracked_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_lf'),
			'value' => 'PICFLF'
		);    
                 
		$this->data['services_pp_tracked_flat_bags_r'] = array();
		
        $this->data['services_pp_tracked_flat_bags_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_dle'),
			'value' => 'PICDLE_PCBRURAL'
		);

		$this->data['services_pp_tracked_flat_bags_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PICFC5_PCBRURAL'
		);
		
		$this->data['services_pp_tracked_flat_bags_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_c4'),
			'value' => 'PICFC4_PCBRURAL'
		);
		
		$this->data['services_pp_tracked_flat_bags_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_lf'),
			'value' => 'PICFFS_PCBRURAL'
		);
		
		$this->data['services_pp_tracked_flat_bags_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_fs'),
			'value' => 'PICFLF_PCBRURAL'
		);    
                 
		$this->data['services_pp_tracked_bubble_bags'] = array();
		
        $this->data['services_pp_tracked_bubble_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PICBC5'
		);

		$this->data['services_pp_tracked_bubble_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_fs'),
			'value' => 'PICBFS'
		);
                 
		$this->data['services_pp_tracked_bubble_bags_r'] = array();
		
		$this->data['services_pp_tracked_bubble_bags_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_c5'),
			'value' => 'PICBC5_PCBRURAL'
		);
		
		$this->data['services_pp_tracked_bubble_bags_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_fs'),
			'value' => 'PICBFS_PCBRURAL'
		);
		
	
        $this->data['services_courier_zonal_across_town_tickets'] = array();
	
		$this->data['services_courier_zonal_across_town_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'NRNTOLA'
		);        

        $this->data['services_courier_zonal_across_town_tickets_r'] = array();
	
		$this->data['services_courier_zonal_across_town_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'NRNTOLA_PCBRURAL'
		);  

        $this->data['services_courier_zonal_across_town_tickets_signature'] = array();
	
		$this->data['services_courier_zonal_across_town_tickets_signature'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'NRSTOLA'
		);        

        $this->data['services_courier_zonal_across_town_tickets_signature_r'] = array();
	
		$this->data['services_courier_zonal_across_town_tickets_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'NRSTOLA_PCBRURAL'
		);         

        $this->data['services_courier_zonal_within_island_tickets'] = array();
	
		$this->data['services_courier_zonal_within_island_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'NRNTOWI'
		);         

        $this->data['services_courier_zonal_within_island_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_10kg'),
			'value' => 'NRNTOWI_NRNTOWI'
		);         

        $this->data['services_courier_zonal_within_island_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_15kg'),
			'value' => 'NRNTOWI_NRNTOWI_NRNTOWI'
		);   

        $this->data['services_courier_zonal_within_island_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_20kg'),
			'value' => 'NRNTOWI_NRNTOWI_NRNTOWI_NRNTOWI'
		);  

        $this->data['services_courier_zonal_within_island_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'NRNTOWI_NRNTOWI_NRNTOWI_NRNTOWI_NRNTOWI'
		);  
        
        $this->data['services_courier_zonal_within_island_tickets_r'] = array();
	
		$this->data['services_courier_zonal_within_island_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'NRNTOWI_PCBRURAL'
		);  

        $this->data['services_courier_zonal_within_island_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_10kg'),
			'value' => 'NRNTOWI_NRNTOWI_PCBRURAL'
		);         

        $this->data['services_courier_zonal_within_island_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_15kg'),
			'value' => 'NRNTOWI_NRNTOWI_NRNTOWI_PCBRURAL'
		);   

        $this->data['services_courier_zonal_within_island_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_20kg'),
			'value' => 'NRNTOWI_NRNTOWI_NRNTOWI_NRNTOWI_PCBRURAL'
		);  

        $this->data['services_courier_zonal_within_island_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'NRNTOWI_NRNTOWI_NRNTOWI_NRNTOWI_NRNTOWI_PCBRURAL'
		);
        
        $this->data['services_courier_zonal_within_island_tickets_signature'] = array();
	
		$this->data['services_courier_zonal_within_island_tickets_signature'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'NRSTOWI'
		);         

        $this->data['services_courier_zonal_within_island_tickets_signature'][] = array(
			'text'  => $this->language->get('text_parcel_weight_10kg'),
			'value' => 'NRSTOWI_NRSTOWI'
		);         

        $this->data['services_courier_zonal_within_island_tickets_signature'][] = array(
			'text'  => $this->language->get('text_parcel_weight_15kg'),
			'value' => 'NRSTOWI_NRSTOWI_NRSTOWI'
		);   

        $this->data['services_courier_zonal_within_island_tickets_signature'][] = array(
			'text'  => $this->language->get('text_parcel_weight_20kg'),
			'value' => 'NRSTOWI_NRSTOWI_NRSTOWI_NRSTOWI'
		);  

        $this->data['services_courier_zonal_within_island_tickets_signature'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'NRSTOWI_NRSTOWI_NRSTOWI_NRSTOWI_NRSTOWI'
		);  
        
        $this->data['services_courier_zonal_within_island_tickets_signature_r'] = array();
	
		$this->data['services_courier_zonal_within_island_tickets_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'NRSTOWI_PCBRURAL'
		);  

        $this->data['services_courier_zonal_within_island_tickets_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_10kg'),
			'value' => 'NRSTOWI_NRSTOWI_PCBRURAL'
		);         

        $this->data['services_courier_zonal_within_island_tickets_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_15kg'),
			'value' => 'NRSTOWI_NRSTOWI_NRSTOWI_PCBRURAL'
		);   

        $this->data['services_courier_zonal_within_island_tickets_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_20kg'),
			'value' => 'NRSTOWI_NRSTOWI_NRSTOWI_NRSTOWI_PCBRURAL'
		);  

        $this->data['services_courier_zonal_within_island_tickets_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'NRSTOWI_NRSTOWI_NRSTOWI_NRSTOWI_NRSTOWI_PCBRURAL'
		);

        $this->data['services_courier_zonal_nationwide_tickets'] = array();
	
		$this->data['services_courier_zonal_nationwide_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'NRNTOII'
		);         

        $this->data['services_courier_zonal_nationwide_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_10kg'),
			'value' => 'NRNTOII_NRNTOII'
		);         

        $this->data['services_courier_zonal_nationwide_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_15kg'),
			'value' => 'NRNTOII_NRNTOII_NRNTOII'
		);   

        $this->data['services_courier_zonal_nationwide_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_20kg'),
			'value' => 'NRNTOII_NRNTOII_NRNTOII_NRNTOII'
		);  

        $this->data['services_courier_zonal_nationwide_tickets'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'NRNTOII_NRNTOII_NRNTOII_NRNTOII_NRNTOII'
		);  
        
        $this->data['services_courier_zonal_nationwide_tickets_r'] = array();
	
		$this->data['services_courier_zonal_nationwide_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'NRNTOII_PCBRURAL'
		);  

        $this->data['services_courier_zonal_nationwide_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_10kg'),
			'value' => 'NRNTOII_NRNTOII_PCBRURAL'
		);         

        $this->data['services_courier_zonal_nationwide_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_15kg'),
			'value' => 'NRNTOII_NRNTOII_NRNTOII_PCBRURAL'
		);   

        $this->data['services_courier_zonal_nationwide_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_20kg'),
			'value' => 'NRNTOII_NRNTOII_NRNTOII_NRNTOII_PCBRURAL'
		);  

        $this->data['services_courier_zonal_nationwide_tickets_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'NRNTOII_NRNTOII_NRNTOII_NRNTOII_NRNTOII_PCBRURAL'
		);
        
        $this->data['services_courier_zonal_nationwide_tickets_signature'] = array();
	
		$this->data['services_courier_zonal_nationwide_tickets_signature'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'NRSTOII'
		);         

        $this->data['services_courier_zonal_nationwide_tickets_signature'][] = array(
			'text'  => $this->language->get('text_parcel_weight_10kg'),
			'value' => 'NRSTOII_NRSTOII'
		);         

        $this->data['services_courier_zonal_nationwide_tickets_signature'][] = array(
			'text'  => $this->language->get('text_parcel_weight_15kg'),
			'value' => 'NRSTOII_NRSTOII_NRSTOII'
		);   

        $this->data['services_courier_zonal_nationwide_tickets_signature'][] = array(
			'text'  => $this->language->get('text_parcel_weight_20kg'),
			'value' => 'NRSTOII_NRSTOII_NRSTOII_NRSTOII'
		);  

        $this->data['services_courier_zonal_nationwide_tickets_signature'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'NRSTOII_NRSTOII_NRSTOII_NRSTOII_NRSTOII'
		);  
        
        $this->data['services_courier_zonal_nationwide_tickets_signature_r'] = array();
	
		$this->data['services_courier_zonal_nationwide_tickets_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_5kg'),
			'value' => 'NRSTOII_PCBRURAL'
		);  

        $this->data['services_courier_zonal_nationwide_tickets_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_10kg'),
			'value' => 'NRSTOII_NRSTOII_PCBRURAL'
		);         

        $this->data['services_courier_zonal_nationwide_tickets_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_15kg'),
			'value' => 'NRSTOII_NRSTOII_NRSTOII_PCBRURAL'
		);   

        $this->data['services_courier_zonal_nationwide_tickets_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_20kg'),
			'value' => 'NRSTOII_NRSTOII_NRSTOII_NRSTOII_PCBRURAL'
		);  

        $this->data['services_courier_zonal_nationwide_tickets_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_weight_25kg'),
			'value' => 'NRSTOII_NRSTOII_NRSTOII_NRSTOII_NRSTOII_PCBRURAL'
		);
      
		$this->data['services_courier_flat_bags'] = array();
	
		$this->data['services_courier_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_dle'),
			'value' => 'NZPRODL'
		);
			
		$this->data['services_courier_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_a5'),
			'value' => 'NZPROA5'
		);
		
		$this->data['services_courier_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_a4'),
			'value' => 'NZPROA4'
		);
		
		$this->data['services_courier_flat_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_lf'),
			'value' => 'NZPROLF'
		);    
				
		$this->data['services_courier_flat_bags_r'] = array();
	
		$this->data['services_courier_flat_bags_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_dle'),
			'value' => 'NZPRODL_PCBRURAL'
		);
			
		$this->data['services_courier_flat_bags_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_a5'),
			'value' => 'NZPROA5_PCBRURAL'
		);
		
		$this->data['services_courier_flat_bags_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_a4'),
			'value' => 'NZPROA4_PCBRURAL'
		);
		
		$this->data['services_courier_flat_bags_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_lf'),
			'value' => 'NZPROLF_PCBRURAL'
		);    

		$this->data['services_courier_bubble_bags'] = array();
				
		$this->data['services_courier_bubble_bags'][] = array(
			'text'  => $this->language->get('text_parcel_size_a5'),
			'value' => 'NZPRBA5'
		);		
				
		$this->data['services_courier_bubble_bags_r'] = array();
			
		$this->data['services_courier_bubble_bags_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_a5'),
			'value' => 'NZPRBA5_PCBRURAL'
		);
	        
		$this->data['services_courier_flat_bags_signature'] = array();
	
		$this->data['services_courier_flat_bags_signature'][] = array(
			'text'  => $this->language->get('text_parcel_size_dle'),
			'value' => 'NZSRODL'
		);
			
		$this->data['services_courier_flat_bags_signature'][] = array(
			'text'  => $this->language->get('text_parcel_size_a5'),
			'value' => 'NZSROA5'
		);
		
		$this->data['services_courier_flat_bags_signature'][] = array(
			'text'  => $this->language->get('text_parcel_size_a4'),
			'value' => 'NZSROA4'
		);
		
		$this->data['services_courier_flat_bags_signature'][] = array(
			'text'  => $this->language->get('text_parcel_size_lf'),
			'value' => 'NZSROLF'
		);    
				
		$this->data['services_courier_flat_bags_signature_r'] = array();
	
		$this->data['services_courier_flat_bags_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_dle'),
			'value' => 'NZSRODL_PCBRURAL'
		);
			
		$this->data['services_courier_flat_bags_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_a5'),
			'value' => 'NZSROA5_PCBRURAL'
		);
		
		$this->data['services_courier_flat_bags_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_a4'),
			'value' => 'NZSROA4_PCBRURAL'
		);
		
		$this->data['services_courier_flat_bags_signature_r'][] = array(
			'text'  => $this->language->get('text_parcel_size_lf'),
			'value' => 'NZSROLF_PCBRURAL'
		);    	
        
		if (isset($this->request->post['nzpost_international_tracking'])) {
			$this->data['nzpost_international_tracking'] = $this->request->post['nzpost_international_tracking'];
		} else {
			$this->data['nzpost_international_tracking'] = $this->config->get('nzpost_international_tracking');
		}
		if (isset($this->request->post['nzpost_international_signature'])) {
			$this->data['nzpost_international_signature'] = $this->request->post['nzpost_international_signature'];
		} else {
			$this->data['nzpost_international_signature'] = $this->config->get('nzpost_international_signature');
		}
		
		$this->template = 'shipping/nzpost.tpl';
		$this->children = array(
			'common/header',
			'common/footer',
		);
		
 		$this->response->setOutput($this->render());
	}
	
	private function validate() {
		if (!$this->user->hasPermission('modify', 'shipping/nzpost')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}

		if (!$this->request->post['nzpost_api_key']) {
			$this->error['api_key'] = $this->language->get('error_api_key');
		}
		
		if (!preg_match('/^[0-9]{4}$/', $this->request->post['nzpost_source_postcode'])){
 			$this->error['source_postcode'] = $this->language->get('error_source_postcode');
		}
		
        if (!$this->request->post['nzpost_length_class_id']) {
			$this->error['length_class_id'] = $this->language->get('error_length_class_id');
		}
        
        if (!$this->request->post['nzpost_weight_class_id']) {
			$this->error['weight_class_id'] = $this->language->get('error_weight_class_id');
		}
        
        if (!$this->request->post['nzpost_currency_code']) {
			$this->error['currency_code'] = $this->language->get('error_currency_code');
		}
        
        
		if (!$this->error) {
			return true;
		} else {
			return false;
		}	
	}
    
    public function install() {
        
        // Set some sensible default settings
        
        $nzpost_defaults = array();
        
        $nzpost_defaults['nzpost_domestic_postage_only'] = 1;

		$this->load->model('setting/setting');
        
        $this->model_setting_setting->editSetting('nzpost', $nzpost_defaults);	
    
    }
}
?>